﻿using System;
using System.Web.UI;
using ltModel;
using ltModel.BLL;
using ltModel.Model;
using System.Collections.Generic;

public partial class ltMan_leaders_leaderAdd : AdminBasePage
{
    ltModel.BLL.ProjectBLL projectBLL = new ltModel.BLL.ProjectBLL();
    ProjectStreetBLL projectStreetBLL = new ProjectStreetBLL();
    ProjectTypeBLL projectTypeBLL = new ProjectTypeBLL();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            List<ProjectStreet> listStreet = projectStreetBLL.GetList();
            ddlStreet.DataSource = listStreet;
            ddlStreet.DataTextField = "StreetName";
            ddlStreet.DataValueField = "StreetID";
            ddlStreet.DataBind();


            List<ProjectType> listType = projectTypeBLL.GetList();
            ddlType.DataSource = listType;
            ddlType.DataTextField = "TypeName";
            ddlType.DataValueField = "TypeID";
            ddlType.DataBind();

            string id = Request.QueryString["ProjectID"] as string;
            if (Str.IsInt(id))
            {
                ltModel.Model.Project project = projectBLL.GetModel(int.Parse(id));
                rtbProjectName.Text = project.ProjectName;
                rtbOrganizor.Text = project.Organizer;
                rtbServiceLocation.Text = project.ServiceLocation;
                rtbProjectContent.Text = project.ProjectContent;
                rtbRecruitmentLocation.Text = project.RecruitmentLocation;
                rtbRecruitmentAmmount.Text = project.RecruitmentAmount.ToString();
                rdpRegistrationDeadLine.SelectedDate = project.RegistrationDeadLine;
                rtbRegistrationRequirement.Text = project.RegistrationRequirement;
                rtbContact.Text = project.Contact;
                ddlStreet.SelectedIndex = ddlStreet.Items.IndexOf(ddlStreet.Items.FindByValue(project.ProjectStreetID.ToString()));
                ddlType.SelectedIndex = ddlType.Items.IndexOf(ddlType.Items.FindByValue(project.ProjectTypeID.ToString()));
                //ruAttachment.Text = project.Attachment;
            }

        }
    }
    protected void RadSave_Click(object sender, EventArgs e)
    {
        string id = Request.QueryString["ProjectID"] as string;
        bool inEdit = Str.IsInt(id);
        ltModel.Model.Project project = null;
        if (inEdit)
            project = projectBLL.GetModel(int.Parse(id));
        else
            project = new ltModel.Model.Project();

        project.ProjectName = DataProtector.ToSBC(rtbProjectName.Text.Trim());
        project.Organizer = DataProtector.ToSBC(rtbOrganizor.Text.Trim());
        project.ServiceLocation = DataProtector.ToSBC(rtbServiceLocation.Text.Trim());
        project.ProjectContent = DataProtector.ToSBC(rtbProjectContent.Text.Trim());
        project.RecruitmentLocation = DataProtector.ToSBC(rtbRecruitmentLocation.Text.Trim());
        project.RecruitmentAmount = DataProtector.ToSBC(rtbRecruitmentAmmount.Text);
        project.RegistrationDeadLine = rdpRegistrationDeadLine.SelectedDate.Value;
        project.RegistrationRequirement = DataProtector.ToSBC(rtbRegistrationRequirement.Text.Trim());
        project.Contact = DataProtector.ToSBC(rtbContact.Text.Trim());
        project.ProjectStreetID = Convert.ToInt32(ddlStreet.SelectedValue);
        project.ProjectTypeID = Convert.ToInt32(ddlType.SelectedValue);
        //project.Attachment = DataProtector.ToSBC(jfly.Text.Trim());

        if (inEdit)
        {
            projectBLL.Update(project);
            //OperateLog.AddSuccessLog(CurrentUser.user_id, Request.UserHostAddress, "领导信息-修改>" + project.sqdw);
        }
        else
        {
            projectBLL.Add(project);
            //OperateLog.AddSuccessLog(CurrentUser.user_id, Request.UserHostAddress, "领导信息-添加>" + ltbo.tname);
        }


        infoPanel.AddSuccessInfo(inEdit ? "修改成功" : "添加成功");
        AddScriptM("setTimeout(parent.reloadData, 300);");
    }
}